#!/bin/bash

# ----------------------------------------------------------------------
# Filename:   mysql_service.sh
# Version:    1.0
# Date:       2013/11/27
# Author:     huijing.hei
# Email:      huijing.hei@cs2c.com.cn
# Summary:    02系统基本功能-04网络服务-03Mysql-02启动/停止Mysql服务
# Notes:       ***
# Copyright:    China Standard Software Co., Ltd.
# History：     
#             Version 1.0, 2013/10/16
#             - Start mysqld service.
# ----------------------------------------------------------------------

##! @TODO: start&stop&restart mysqld service
##! @AUTHOR: huijing.hei
##! @VERSION: 1.0 
##! @OUT: 0 => success; 1 => failure

function do_test()
{

    serv=mysqld

CheckServiceExists ${serv}

if [ $? -ne 0 ];then
    echo "mysqld.service or mysqld not exists"
    CheckServiceExists mariadb
    EchoResult "mariadb.service or mariadb exists"
    serv=mariadb
fi

    StatusDaemon ${serv}

    # start
    if [ $? -ne 0 ]
    then
        echo "${serv} is stopped"
        StartDaemon ${serv}
    else
        echo "${serv} is running..."
    fi 

    sleep 3
    # check mysqld start
    StatusDaemon ${serv}
    EchoResult "service ${serv} start"

    # restart
    RestartDaemon ${serv}

    sleep 3
    # check mysqld restart
    StatusDaemon ${serv}
    EchoResult "service ${serv} restart"

    # stop
    StopDaemon ${serv}

    # check mysqld stop
    ! StatusDaemon ${serv}
    EchoResult "service ${serv} stop"

}


# include lib files

if [ -z "$SFROOT" ]
then
    echo "SFROOT is null, pls check"
    exit 1
fi

. ${SFROOT}/lib/Echo.sh
. ${SFROOT}/lib/NetOps.sh
. ${SFROOT}/lib/Check.sh

do_test || EchoResult "testcase: ${serv} start,stop,restart"
echo ""
